import { MockMethod } from 'vite-plugin-mock';
import { resultError, resultSuccess, getRequestToken, requestParams } from '../_util';

export function createFakeUserList() {
  return [
    {
      userId: '1',
      username: 'vben',
      realName: 'Vben Admin',
      avatar: 'https://q1.qlogo.cn/g?b=qq&nk=190848757&s=640',
      desc: 'manager',
      password: '123456',
      token: 'fakeToken1',
      // homePath: '/dashboard/analysis',
      homePath: '/dashboard',
      roles: [
        {
          roleName: 'Super Admin',
          value: 'super',
        },
      ],
    },
    {
      userId: '2',
      username: 'test',
      password: '123456',
      realName: 'test user',
      avatar: 'https://q1.qlogo.cn/g?b=qq&nk=339449197&s=640',
      desc: 'tester',
      token: 'fakeToken2',
      homePath: '/dashboard/workbench',
      roles: [
        {
          roleName: 'Tester',
          value: 'test',
        },
      ],
    },
  ];
}

const fakeCodeList: any = {
  '1': ['1000', '3000', '5000'],

  '2': ['2000', '4000', '6000'],
};
export const data = [
  {
    id: 35,
    username: 'userchuangli',
    password: null,
    customer: 'chuangli',
    clientType: 'CUSTOMER',
    createTime: '2024-05-09 14:48:41',
    updateTime: '2024-05-09 06:48:47',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '130000',
    city: '130500',
    accountManager: '一',
    contact: '12312312312',
    detailedAddress: '海悦大街',
    enterprise: false,
  },
  {
    id: 34,
    username: 'lxl',
    password: null,
    customer: 'lxl',
    clientType: 'ENTERPRISE',
    createTime: '2024-02-05 14:17:22',
    updateTime: '2024-02-05 14:46:42',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '140000',
    city: '140300',
    accountManager: '123',
    contact: '11111111111',
    detailedAddress: 'lxl',
    enterprise: true,
  },
  {
    id: 31,
    username: 'shiwei1',
    password: null,
    customer: 'sw',
    clientType: 'CUSTOMER',
    createTime: '2024-01-29 09:24:55',
    updateTime: '2024-02-05 08:37:41',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '110000',
    city: '110000',
    accountManager: 'w',
    contact: '19322932321',
    detailedAddress: '1sadasda',
    enterprise: false,
  },
  {
    id: 30,
    username: 'chuangli',
    password: null,
    customer: 'chuangli',
    clientType: 'CUSTOMER',
    createTime: '2023-11-28 14:30:26',
    updateTime: '2023-11-28 14:30:27',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '130000',
    city: '130100',
    accountManager: 'tim',
    contact: '12312312301',
    detailedAddress: '创力',
    enterprise: false,
  },
  {
    id: 29,
    username: 'wangwei',
    password: null,
    customer: 'wangwei',
    clientType: 'ENTERPRISE',
    createTime: '2023-11-02 16:09:38',
    updateTime: '2024-02-04 16:19:38',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '150000',
    city: '150500',
    accountManager: 'wangwei',
    contact: '2134124',
    detailedAddress: 'dfad',
    enterprise: true,
  },
  {
    id: 27,
    username: 'sssssss',
    password: null,
    customer: 'dasdadssss',
    clientType: 'ENTERPRISE',
    createTime: '2023-11-02 11:13:34',
    updateTime: '2023-11-02 15:02:16',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '210000',
    city: '210800',
    accountManager: 'dsadasd',
    contact: 'dsadasda',
    detailedAddress: 'dsadasdasd',
    enterprise: true,
  },
  {
    id: 26,
    username: 'dadad',
    password: null,
    customer: 'dasda',
    clientType: 'ENTERPRISE',
    createTime: '2023-11-02 11:02:07',
    updateTime: '2023-11-02 11:02:07',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '140000',
    city: '140300',
    accountManager: 'dasdasd',
    contact: 'asdasd',
    detailedAddress: 'dasdasd',
    enterprise: true,
  },
  {
    id: 25,
    username: 'dadsdas',
    password: null,
    customer: 'dasdasd',
    clientType: 'ENTERPRISE',
    createTime: '2023-11-02 10:13:07',
    updateTime: '2023-11-02 10:13:08',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '140000',
    city: '140400',
    accountManager: 'asdasdasd',
    contact: 'asdasd',
    detailedAddress: 'dasdasdasd',
    enterprise: true,
  },
  {
    id: 24,
    username: 'lisi',
    password: null,
    customer: 'LI',
    clientType: 'CUSTOMER',
    createTime: '2023-11-02 09:25:28',
    updateTime: '2023-11-02 09:44:25',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '150000',
    city: '150500',
    accountManager: '改客户负责人',
    contact: '10987654321',
    detailedAddress: '亮马桥',
    enterprise: false,
  },
  {
    id: 15,
    username: 'shiwei',
    password: null,
    customer: '石伟',
    clientType: 'ENTERPRISE',
    createTime: '2023-11-01 17:14:31',
    updateTime: '2023-11-02 09:10:53',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '130000',
    city: '130600',
    accountManager: '石伟123',
    contact: '17600608660',
    detailedAddress: 'asdasd',
    enterprise: true,
  },
  {
    id: 14,
    username: 'zhangsan',
    password: null,
    customer: 'ZHANG',
    clientType: 'ENTERPRISE',
    createTime: '2023-11-01 10:47:09',
    updateTime: '2023-11-02 15:02:45',
    token: null,
    pageNum: null,
    pageSize: null,
    province: '150000',
    city: '150900',
    accountManager: '改客户负责人',
    contact: '10987654321',
    detailedAddress: '1233333',
    enterprise: true,
  },
  {
    id: 11,
    username: 'admin',
    password: null,
    customer: '创力科技',
    clientType: 'ENTERPRISE',
    createTime: '2023-10-13 09:21:40',
    updateTime: '2023-10-27 15:25:11',
    token: null,
    pageNum: null,
    pageSize: null,
    province: null,
    city: null,
    accountManager: null,
    contact: null,
    detailedAddress: null,
    enterprise: true,
  },
  {
    id: 10,
    username: 'yzm',
    password: null,
    customer: 'YZM',
    clientType: 'ENTERPRISE',
    createTime: '2023-10-09 16:14:24',
    updateTime: '2023-10-12 17:03:39',
    token: null,
    pageNum: null,
    pageSize: null,
    province: null,
    city: null,
    accountManager: null,
    contact: null,
    detailedAddress: null,
    enterprise: true,
  },
  {
    id: 9,
    username: 'mm',
    password: null,
    customer: 'YZM',
    clientType: 'CUSTOMER',
    createTime: '2023-10-09 16:02:22',
    updateTime: '2023-10-12 17:03:23',
    token: null,
    pageNum: null,
    pageSize: null,
    province: null,
    city: null,
    accountManager: null,
    contact: null,
    detailedAddress: null,
    enterprise: false,
  },
  {
    id: 4,
    username: 'sunpeihua',
    password: null,
    customer: 'SPH',
    clientType: 'CUSTOMER',
    createTime: '2023-10-08 11:13:10',
    updateTime: '2023-10-12 17:03:17',
    token: null,
    pageNum: null,
    pageSize: null,
    province: null,
    city: null,
    accountManager: null,
    contact: null,
    detailedAddress: null,
    enterprise: false,
  },
];
export default [
  // mock user login
  {
    url: '/basic-api/login',
    timeout: 200,
    method: 'post',
    response: ({ body }) => {
      const { username, password } = body;
      const checkUser = createFakeUserList().find(
        (item) => item.username === username && password === item.password,
      );
      if (!checkUser) {
        return resultError('Incorrect account or password！');
      }
      const { userId, username: _username, token, realName, desc, roles } = checkUser;
      return resultSuccess({
        roles,
        userId,
        username: _username,
        token,
        realName,
        desc,
      });
    },
  },
  {
    url: '/basic-api/getUserInfo',
    method: 'get',
    response: (request: requestParams) => {
      const token = getRequestToken(request);
      if (!token) return resultError('Invalid token');
      const checkUser = createFakeUserList().find((item) => item.token === token);
      if (!checkUser) {
        return resultError('The corresponding user information was not obtained!');
      }
      return resultSuccess(checkUser);
    },
  },
  {
    url: '/basic-api/getPermCode',
    timeout: 200,
    method: 'get',
    response: (request: requestParams) => {
      const token = getRequestToken(request);
      if (!token) return resultError('Invalid token');
      const checkUser = createFakeUserList().find((item) => item.token === token);
      if (!checkUser) {
        return resultError('Invalid token!');
      }
      const codeList = fakeCodeList[checkUser.userId];

      return resultSuccess(codeList);
    },
  },
  {
    url: '/basic-api/logout',
    timeout: 200,
    method: 'get',
    response: (request: requestParams) => {
      const token = getRequestToken(request);
      if (!token) return resultError('Invalid token');
      const checkUser = createFakeUserList().find((item) => item.token === token);
      if (!checkUser) {
        return resultError('Invalid token!');
      }
      return resultSuccess(undefined, { message: 'Token has been destroyed' });
    },
  },
  {
    url: '/basic-api/plc/user/list',
    timeout: 200,
    method: 'post',
    response: (request: requestParams) => {
      return resultSuccess(data);
    },
  },
  {
    url: '/basic-api/plc/register',
    timeout: 200,
    method: 'post',
    response: (request: requestParams) => {
      return resultSuccess('添加成功');
    },
  },
  {
    url: '/basic-api/plc/user/editInfo',
    timeout: 200,
    method: 'post',
    response: (request: requestParams) => {
      return resultSuccess('编辑成功');
    },
  },
] as MockMethod[];
